<?php

	/**
	* Check to see if user is logged in, if not display login form
	**/
	
	if (isloggedin()) forward('pg/dashboard/');
	
	//Load the front page
	global $CONFIG;
	// Sets the number of contents to display for each category
	$perCatDisplay = 1;

    // Allows the header to know wether or not to load the swf javascript
    global $uvsq_index;
    $uvsq_index = true;
	// Get configuration settings
	$config = find_plugin_settings('categories');
	$cats = json_decode($config->categories, true);
	$content = '<div id="myContent">
<img src="'.$CONFIG->wwwroot.'mod/theme_uvsq/graphics/image_accueil.jpg"></img>		</div>';
	
	if (is_array($cats)){
		$cats = $cats['categories']['main'];
		$i = 0;
		
		foreach ($cats as $supCat){
			$content .= '<div class="'.$supCat['class'].' uvsq">';
			$content .= elgg_view('page_elements/index_title', array('title' => $supCat['value']));
			set_context('index');
			$content .= list_entities_from_categories($perCatDisplay, (string) $i);
			$content .= '</div>';
			set_context('main');
			$i++;
		}
	}	
		
			
	global $autofeed;
	$autofeed = false;
	$content = elgg_view_layout('two_column_left_sidebar_uvsq', '', $content, elgg_view("account/forms/login"),  elgg_view("navigation/logout_search") . elgg_view("output/tagcloud"));
	echo page_draw(null, $content);
	
	function list_entities_from_categories($limit, $cat){
		$offset = (int) get_input('offset');
		$limit = (int) $limit;
		$count = get_entities_from_metadata('supCat', $cat, '', '', 0, $limit, $offset, "", 0, true);
		$entities = get_entities_from_metadata('supCat', $cat, '', '', 0, $limit, $offset, "", 0, false);
		return elgg_view_entity_list($entities, $count, $offset, $limit, false, false, false);
	}

?>